package com.hmy.material.controller;

import com.hmy.material.domain.HmyMateriaFeedConsume;
import com.hmy.material.mapper.ConsumeMapper;
import com.hmy.material.service.ConsumeService;
import com.hmy.material.service.StoreService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zxh
 * @version 1.0
 * @description: 物料消耗controller控制器
 * @date 2024/2/1 11:53
 */
@RestController
@RequestMapping("/consume")
public class ConsumeController extends BaseController {

    @Resource
    private ConsumeService consumeService;

    @Resource
    private StoreService storeService;
    @Resource
    private ConsumeMapper consumeMapper;

    /**
     * @param
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @description 获取所有表格编码
     * @author ljy
     * @date 2024/2/22 15:51:29
     */
    @GetMapping("/findCode")
    public AjaxResult findCode() {
        return AjaxResult.success(consumeMapper.findPhouseCode());
    }

    @GetMapping("/listMsg")
    public TableDataInfo selectMsgList(Integer position, Integer type,
                                       String dateStart, String dateEnd, String phouseCode) {
        System.out.println("========>");
        List<HmyMateriaFeedConsume> consumeList = consumeService.selectConsumeList(position, type, dateStart, dateEnd, phouseCode);
        return getDataTable(consumeList);
    }

    @GetMapping("list")
    public TableDataInfo selectConsumeList(Integer position, Integer type,
                                           String dateStart, String dateEnd, String equipmentPhouseCode) {
        startPage();
        List<HmyMateriaFeedConsume> consumeList = consumeService.selectConsumeList(position, type, dateStart, dateEnd, equipmentPhouseCode);
        return getDataTable(consumeList);
    }


    @PostMapping("add")
    public AjaxResult addConsume(@RequestBody HmyMateriaFeedConsume consume) {
        return toAjax(consumeService.addConsume(consume));
    }

    @RequiresPermissions("material:consume:query")
    @GetMapping("getInfo/{id}")
    public AjaxResult selectConsumeById(@PathVariable Long id) {
        return AjaxResult.success(consumeService.selectConsumeById(id));
    }

    @RequiresPermissions("material:consume:update")
    @PostMapping("update")
    public AjaxResult updateConsume(@RequestBody HmyMateriaFeedConsume consume) {
        return toAjax(consumeService.updateConsume(consume));
    }


    @DeleteMapping("del/{delIds}")
    //@RequiresPermissions("material:consume:del")
    public AjaxResult delConsumeById(@PathVariable Long[] delIds) {
        return toAjax(consumeService.delConsumeByIds(delIds));
    }


    @GetMapping("findPhouseCode")
    public AjaxResult findPhouseCode() {
        return AjaxResult.success(consumeService.findAllPhouseCode());
    }

    @GetMapping("findAllStaffName")
    public AjaxResult findAllStaffName() {
        return AjaxResult.success(consumeService.findAllStaffName());
    }

    /**
     * 根据仓库查询该仓库下饲料类型
     */
    @GetMapping("findStoreFeedTypeByPosition")
    public AjaxResult findStoreFeedTypeByPosition(@RequestParam(value = "position") String position) {
        return AjaxResult.success(storeService.findStoreFeedTypeByPosition(position));
    }

    @GetMapping("findStoreNum")
    public AjaxResult findStoreNum(String type, String position) {
        return AjaxResult.success(storeService.findStoreByTypePosition(type, position));
    }
}
